//
//  ZCXFirstActivityDetialTableViewCell.m
//  LoveOfPet
//
//  Created by dllo on 15/11/14.
//  Copyright © 2015年 孔维. All rights reserved.
//

#import "ZCXFirstActivityDetialTableViewCell.h"
#define HEIGHT  [[UIScreen mainScreen]bounds].size.height / 667
#define WIDTH   [[UIScreen mainScreen]bounds].size.width / 375
@interface ZCXFirstActivityDetialTableViewCell ()
@property (nonatomic, retain) UILabel *messageLabel;
@property (nonatomic, retain) UILabel *titleLabel;
@property (nonatomic, retain) UIView *lineView;
@end

@implementation ZCXFirstActivityDetialTableViewCell
- (void)dealloc{
    [_lineView release];
    [_titleLabel release];
    [_messageLabel release];
    [_activity release];
    
    [super dealloc];
}
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.titleLabel = [[UILabel alloc]init];
        [self.contentView addSubview:_titleLabel];
        [_titleLabel release];
        self.messageLabel = [[UILabel alloc]init];
        [self.contentView addSubview:_messageLabel];
        [_messageLabel release];
        self.lineView = [[UIView alloc]init];
        [self.contentView addSubview:_lineView];
        [_lineView release];
    }
    return self;
}
- (void)layoutSubviews{
    [super layoutSubviews];
    self.titleLabel.frame = CGRectMake(self.frame.size.width / 2 - 100 * WIDTH, 10 * HEIGHT, 200 * WIDTH, 30 * HEIGHT);
    self.lineView.frame = CGRectMake(10 * WIDTH, self.titleLabel.frame.size.height + 20 * HEIGHT, self.frame.size.width - 20 * WIDTH, 1 * HEIGHT);
    self.lineView.backgroundColor = [UIColor grayColor];
    self.messageLabel.frame = CGRectMake(10 * WIDTH, self.titleLabel.frame.size.height + 30 * HEIGHT, self.frame.size.width - 20 * WIDTH, self.heigth * HEIGHT);
    
}
- (void)setActivity:(ActivityModel *)activity{
    if (_activity != activity) {
        [_activity release];
        _activity = [activity retain];
    }
    self.titleLabel.textAlignment = NSTextAlignmentCenter;
    self.titleLabel.text = activity.tag;
    self.messageLabel.numberOfLines = 0;
    self.messageLabel.textColor = [UIColor grayColor];
    self.messageLabel.text = activity.message;
    
   self.heigth = [ZCXFirstActivityDetialTableViewCell heigthOfmessageLabel:self.messageLabel.text andFont:[UIFont systemFontOfSize:15 * WIDTH] andWidth:self.frame.size.width - 20 * WIDTH];
}
+ (CGFloat)heigthOfmessageLabel:(NSString *)text andFont:(UIFont *)font andWidth: (CGFloat)width{
    CGSize size = CGSizeMake(width, MAXFLOAT);
    NSDictionary *dic = [NSDictionary dictionaryWithObject:font forKey:NSFontAttributeName];
    CGRect frame = [text boundingRectWithSize:size options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
    return frame.size.height;
}
- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
